﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Globalization;

namespace DiaryPlanner
{
    public partial class Planner : UserControl
    {
        PlannerMonth plannerMonth = new PlannerMonth();
        PlannerWeek plannerWeek = new PlannerWeek();
        PlannerDay plannerDay = new PlannerDay();
             
        public Planner()
        {
            InitializeComponent();
            initPlanner();
        }

        private void initPlanner()
        {
            plannerMonth.savePlanner(this);
            plannerWeek.savePlanner(this);
            plannerDay.savePlanner(this);

            monthButton.Checked = true;
            monthButton_CheckedChanged();
            setDateLabel();
        }

        private void monthCalendar1_DateSelected(object sender, DateRangeEventArgs e)
        {
            setDateLabel();
        }

        private void monthCalendar1_DateChanged(object sender, DateRangeEventArgs e)
        {
            setDateLabel();
        }

        private void dayButton_CheckedChanged(object sender, EventArgs e)
        {
            this.calendarpanel.Controls.Clear();
            this.calendarpanel.Controls.Add(plannerDay);
        }

        private void weekButton_CheckedChanged(object sender, EventArgs e)
        {
            this.calendarpanel.Controls.Clear();
            this.calendarpanel.Controls.Add(plannerWeek);
        }

        private void monthButton_CheckedChanged(object sender, EventArgs e)
        {
            this.calendarpanel.Controls.Clear();
            this.calendarpanel.Controls.Add(plannerMonth);
        }

        private void monthButton_CheckedChanged()
        {
            monthButton_CheckedChanged(null,null);
        }

        private void setDateLabel()
        {
            plannerMonth.myDT = monthCalendar1.SelectionStart;
            plannerMonth.viewMonth();

            dateLabel.Text = monthCalendar1.SelectionStart.Year.ToString() + "년 " +
                             monthCalendar1.SelectionStart.Month.ToString() + "월 " +
                             monthCalendar1.SelectionStart.Day.ToString() + "일" + " (" +
                             monthCalendar1.SelectionStart.DayOfWeek.ToString()+")";

            plannerMonth.month_Click(plannerMonth.getMonthList
                (monthCalendar1.SelectionStart.Day+plannerMonth.getFirstWeek()));
        }
    }
}
